﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wpf.Telemetry.TestApp
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            doStuff.Click += new RoutedEventHandler(doStuff_Click);
            badButton.Click += new RoutedEventHandler(badButton_Click);

            CommandBinding openBinding = new CommandBinding(ApplicationCommands.New, this.NewCommandHandler);
            this.CommandBindings.Add(openBinding);
        }

        void badButton_Click(object sender, RoutedEventArgs e)
        {
            string s = null;
            MessageBox.Show(s.Length.ToString()); // this will cause a null reference exception to be thrown
        }

        void doStuff_Click(object sender, RoutedEventArgs e)
        {
            // most basic scenario - adding telemetry to a method called by the UI
            App.CurrentInstance.Monitoring.RecordFeatureUsage("DoStuff");
        }

        public void NewCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            
            App.CurrentInstance.Monitoring.RecordFeatureUsage("Application.New", e.Source);
        }


    }
}
